//
//  LDBossFinderResumeExpRowView.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/6/8.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class LDBossFinderResumeExpRowView: UIView {
    
    var divideLine:UIImageView?
    var companyName:UILabel?
    var jobName:UILabel?
    var jobTag:UILabel?//标签
    var jobDescLab:UILabel?
    
    var timeLab:UILabel?
    
    let SameLabTag = 333
    
    var model = LDBossFinderResumeExpCellModels_details() {
        
        didSet{
            updateFrame()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setDefaultContent()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setDefaultContent() {
        
        self.frame = LDFrame.ScreenBounds
        
        companyName = UILabel.setDetailsLab("互联网 | 杭州乐电网络科技有限公司", fontSize: 15, titleColor:LDFontColor.Green,Alignment: .Left)
        timeLab = UILabel.setDetailsLab("2011 - 2015", fontSize: 13, titleColor:LDFontColor.DeepGray,Alignment: .Right)
        jobName = UILabel.setDetailsLab("设计师 | 视觉设计", fontSize: 14, titleColor:LDFontColor.DeepGray,Alignment: nil)
        jobDescLab = UILabel.setDetailsLab("", fontSize: 13, titleColor: LDFontColor.LightGray,Alignment: nil)
        
        
        divideLine = UIImageView.setupDivideLine_H(LDFrame.ScreenWidth - LDCellFrame.Margin_H)
        addSubview(divideLine!)
        addSubview(companyName!)
        addSubview(timeLab!)
        addSubview(jobName!)
        addSubview(jobDescLab!)
        
        
        divideLine?.snp_makeConstraints(closure: { (make) in
            make.top.left.right.equalTo(0)
            make.height.equalTo(1)
        })
        
        companyName?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo((divideLine?.snp_bottom)!).offset(LDMargin_V*3)
            make.left.equalTo(0)
            make.height.equalTo(20)
            make.width.lessThanOrEqualTo(200)
        })
        
        timeLab?.snp_makeConstraints(closure: { (make) in
            make.right.equalTo(0)
            make.width.equalTo(120)
            make.height.equalTo(15)
            make.centerY.equalTo((companyName?.snp_centerY)!)
            
        })
        jobName?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo((companyName?.snp_bottom)!).offset(LDMargin_V*1.5)
            make.left.equalTo(companyName!)
            make.height.equalTo(20)
            make.width.lessThanOrEqualTo(300)
        })
        

        jobDescLab?.snp_makeConstraints(closure: { (make) in
            make.left.right.equalTo(0)
            make.height.equalTo(0)

        })
    }
    
    //更新
    func updateFrame() {
        
        companyName?.text = "\(model.companyname) | \(model.industryname)"
        jobName?.text = "\(model.jobtitle) | \(model.department)"
        timeLab?.text = "\(model.startdate) - \(model.enddate)"
        
        //显示labs个数
        let Y = LDMargin_V*3 + LDCellFrame.LabsH + 20 + LDMargin_V
        
        let jobstrenthStrArr = model.jobstrenths ?? [String]()
    
        UILabel.creatLabsFromArrTags(jobstrenthStrArr, labsTag: SameLabTag, labH: 20, font: LDFont.Font13, toView: self, originX: 0, originY: Y, marginX: 13, marginY: 13)
        
        jobDescLab?.attributedText = String.getAttrFormString(lineH: 6, text: model.jobdesc,font:LDFont.Font14)

        //按照cell的标签个数判断位置
        let countLabs = model.jobstrenths.count
        if countLabs > 0 {
            let labsCount = self.viewWithTag(countLabs+SameLabTag-1) as! UILabel
            
            jobDescLab?.snp_updateConstraints(closure: { (make) in
                make.top.equalTo(labsCount.snp_bottom).offset(Margin_V)
                make.height.equalTo(model.jobDescH)

            })
            
        } else {
            
            jobDescLab?.snp_updateConstraints(closure: { (make) in
                make.top.equalTo(jobName!.snp_bottom).offset(Margin_V)
                make.height.equalTo(model.jobDescH)
            })
        }
    }
    
}